package org.chen.bas.util;

import com.baidu.aip.contentcensor.AipContentCensor;
import com.baidu.aip.contentcensor.EImgType;
import org.json.JSONObject;

public class AuditUtils {
    //设置APPID/AK/SK
    public static final String APP_ID ="78965239";
    public static final String API_KEY = "xF0N3lNluqnXHOyIsales80r";
    public static final String SECRET_KEY = "5yLSqdJd33N1h4KDm8u1kZVC9jgQ6hmi";


    public static boolean auditImg(String path){
        try {
            // 初始化一个AipContentCensor
            AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);

            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            JSONObject res = client.imageCensorUserDefined(path, EImgType.URL, null);
            String conclusion = res.getString("conclusion");
            if ("合规".equals(conclusion)){
                return true;
            }else {
                return false;
            }


        } catch (Exception e) {
            e.printStackTrace();
            return  false;
        }

    }
    public static boolean auditText(String text){
        try {
            // 初始化一个AipContentCensor
            AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);

            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            JSONObject jsonObject = client.textCensorUserDefined(text);
            String conclusion = jsonObject.getString("conclusion");
            if ("合规".equals(conclusion)){
                return true;
            }else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return  false;
        }
    }

    public static void main(String[] args) {
        System.out.println(auditText("流寇"));
    }

}
